package edu.tum.cs.i1.pse;

import java.util.Iterator;

public class StringWordsIterator implements Iterator<String> {
	
	private String[] words;
	private int position = 0;

	public StringWordsIterator(String sentence) {
		words = sentence.split(" ");
	}
	
	@Override
	public boolean hasNext() {
		if(position >= words.length || words[position] == null)
			return false;
		else
			return true;
	}

	@Override
	public String next() {
		return words[position++];
	}

	@Override
	public void remove() {
		String[] temp = new String[words.length-1];
		for(int i=0; i<temp.length; i++) {
			if (i>=position)
				temp[i] = words[i+1];
			else
				temp[i] = words[i];
		}
		words = temp;
	}



}
